package com.analysis.apresunday.service.impl;

import com.analysis.apresunday.mapper.AnalysisSalaryMapper;
import com.analysis.apresunday.entity.po.AnalysisSalary;
import com.analysis.apresunday.service.AnalysisSalaryService;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.stereotype.Service;

import java.util.Comparator;
import java.util.List;

@Service
public class AnalysisSalaryServiceImpl extends ServiceImpl<AnalysisSalaryMapper, AnalysisSalary> implements AnalysisSalaryService {

    @Override
    public List<AnalysisSalary> getSalaryList() {
        QueryWrapper<AnalysisSalary> query = new QueryWrapper<>();
        // 按照创建时间获取最新的10条数据
        query.orderByDesc("create_time");
        query.last("limit 10");
        List<AnalysisSalary> analysisSalaries = baseMapper.selectList(query);
        // 工资高的排前面
        analysisSalaries.sort(Comparator.comparing(AnalysisSalary::getAvgSalary));
        return analysisSalaries;
    }
}
